import { HubConnectionBuilder, LogLevel } from '@aspnet/signalr'

export const createConsumer = (connected, received, accountId, userId, token) => {
  const connection = new HubConnectionBuilder()
    .withUrl(`http://localhost:44300/signalr-hubs/chat?type=user&accountId=${accountId}&userId=${userId}`,
    {
      accessTokenFactory: () => token
    })
    .configureLogging(LogLevel.Information)
    .build()

  connection.on('receiveMessage', received)
  connection.on('Connected', connected)
  // connection.on('ReceiveMessage', function (event, message) {
  //   console.log(event + ',' + message)
  // })
  connection.start()

  return connection
}

// const connection = new HubConnectionBuilder()
//   .withUrl('http://localhost:5000/question-hub')
//   .configureLogging(LogLevel.Information)
//   .build()

// connection.on('ReceiveMessage', function (message) {
//   console.log(message)
// })

// connection.start()
